package com.zyz.L_泛型.泛型使用;

import java.util.*;

/**
 * @author: vick
 * @Date: 2025/4/2
 * @Description:
 * @version: 1.0
 */
public class Demo2 {
    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("Vick", 18);
        map.put("nana", 28);
        map.put("lili", 38);
        //map.put(11, "aaa"); //编译错误

        //遍历key
        Set<String> strings = map.keySet();
        for (String string : strings) {
            System.out.println(string);
        }

        //遍历value
        Collection<Integer> values = map.values();
        Iterator<Integer> iterator = values.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        //entry
        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
        Iterator<Map.Entry<String, Integer>> iterator1 = entrySet.iterator();
        while (iterator1.hasNext()) {
            Map.Entry<String, Integer> next = iterator1.next();
            System.out.println(next);
            String key = next.getKey();
            Integer value = next.getValue();
            System.out.println(key + ": " + value);
        }
    }
}
